import json

total_data = {
    "testResult": [],
    "testPass": 0,
    "testName": "蜗牛进销存",
    "testAll": 12,
    "testFail": 2,
    "beginTime": 2,
    "totalTime": 2,
    "testSkip": 3,
    "testError": 0
}

case_data = {
    "caseid": "test_barcode_001",
    "caseModule": "销售出库",
    "testData": "",  # 输入参数
    "description": "验证输入正确的条码扫码成功",
    "spendTime": 0.04,
    "status": 2,
    "log": []
}


# todo  将测试数据 存入数据库
def write_data_to_db():
    pass


# 将数据从数据库取出来
def get_data_from_db():
    pass


class Report:
    def __init__(self, report_name="接口自动化报告.html"):
        self.report_name = report_name

    def generate_report(self):
        # 打开模板 ==读取所有内容
        with open("./蜗牛进销存v1.3.html", 'r', encoding='utf-8') as fb:
            content = fb.read()
            # 替换标题
            content = content.replace("${title}", "xx项目自动化报告")
            # 拼凑测试数据 ---dict
            # total_data["testResult"].append(case_data)

            result = json.dumps(total_data)

            # 替换报告正文
            content = content.replace("${result}", result)

            # 将报告内容 写入 新的文档
            with open(self.report_name, "w", encoding='utf-8') as f:
                f.write(content)


if __name__ == '__main__':
    re = Report()
    re.generate_report()
